<script>
function confirm_uninstall(item, url){
Sexy.confirm('<h1><?php echo Lang::getBackGlobal('install_confirm'); ?> '+item+' ?</h1><p><p><?php echo Lang::getBackGlobal('install_confirm2'); ?></p>', {onComplete: 
          function(returnvalue) { 
            if(returnvalue)
            {
              window.location.href = url;
            }
          }
        });
}
</script>
<?php

/**
 * @author 
 * @copyright 2009
 */

if($_SESSION['rank'] < 4){
	exit(Lang::getBackGlobal('wrong_permissions'));
}

class Install{
	public static function createPermissions($com, $front, $back){
		$com = System::$db->real_escape_string($com);
		$front = System::$db->real_escape_string($front);
		$back = System::$db->real_escape_string($back);
		
		$query = System::$db->query("INSERT INTO {prefix}permissions(component, backend, frontend) VALUES ('".$com."', '".$back."', '".$front."')");
		if($query){
			return true;
		}else{
			return false;
		}
		
	}
	
	public static function deletePermissions($com){
		$com = System::$db->real_escape_string($com);
		
		$query = System::$db->query("DELETE FROM {prefix}permissions WHERE component = '".$com."'");
		
		if($query){
			return true;
		}else{
			return false;
		}
		
	}
	
	public static function exuteSql($sql){
		ob_start();
		echo $sql;
		$str_buffer = ob_get_contents();
		ob_end_clean();

		$install = System::$db->multi_query($str_buffer);
		
		return $install;
	}
}

function chmod_R($path, $filemode) { 
    if (!is_dir($path)) 
        return chmod($path, $filemode); 

    $dh = opendir($path); 
    while (($file = readdir($dh)) !== false) { 
        if($file != '.' && $file != '..') { 
            $fullpath = $path.'/'.$file; 
            if(is_link($fullpath)) 
                return FALSE; 
            elseif(!is_dir($fullpath)) 
                if (!chmod($fullpath, $filemode)) 
                    return FALSE; 
            elseif(!chmod_R($fullpath, $filemode)) 
                return FALSE; 
        } 
    } 

    closedir($dh); 

    if(chmod($path, $filemode)) 
        return TRUE; 
    else 
        return FALSE; 
}

function rmdirr($dirname)
{
    if (!file_exists($dirname)) {
        return false;
    }

    if (is_file($dirname) || is_link($dirname)) {
        return unlink($dirname);
    }

    $dir = dir($dirname);
    while (false !== $entry = $dir->read()) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }

        rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
    }

    $dir->close();
    return rmdir($dirname);
}

$ext = array('zip');

switch($_GET['type']){
	case 'mod':
	 require_once 'module.php';
	 break;
 	case 'com':
	 require_once 'component.php';
	 break;
 	case 'tlp':
	 require_once 'template.php';
	 break;
	 
	 case 'del_mod':
	 require_once 'del_module.php';
	 break;
	 case 'del_com':
	 require_once 'del_component.php';
	 break;
	 case 'del_tlp':
	 require_once 'del_template.php';
	 break;
	 
	 
 	default:
	 require_once 'wizard.php';
	 break;
}

?>